package com.ma.service.impl;

import com.ma.dto.PostsDTO;
import com.ma.entity.Posts;
import com.ma.mapper.PostsMapper;
import com.ma.service.PostsService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class PostsServiceImpl implements PostsService {

    @Autowired
    private PostsMapper postsmapper;
    @Override
    public void save(PostsDTO postsDTO) {
        Posts posts = new Posts();
        BeanUtils.copyProperties(postsDTO, posts);
        posts.setCreatedTime(LocalDateTime.now());
        posts.setLikes(0);
        postsmapper.save(posts);
    }

    @Override
    public List<Posts> list() {
        return postsmapper.list();
    }
}
